package com.xyh.affairs.aspect;

import com.xyh.affairs.communication.TransactionMs;
import com.xyh.affairs.communication.TransactionVo;
import com.xyh.affairs.connection.YhConnection;
import com.xyh.affairs.utils.TransactionType;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.core.Ordered;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

/**
 * @version v1.0
 * @类描述：
 * @项目名称：
 * @包名： com.xyh.affairs.aspect
 * @类名称：AspestAnnotion
 * @创建人：YIHANG.XU
 * @创建时间：2020/8/91:39 下午
 * @修改人：YIHANG.XU
 * @修改时间：2020/8/91:39 下午
 * @修改备注：
 * @Copyright
 */
@Aspect
@Component
public class AspestAnnotion implements Ordered {
    @Around("@annotation(com.xyh.affairs.annotion.Yhtransactional)")
    public void invoke(ProceedingJoinPoint point) throws ClassNotFoundException {
        //创建事务开启事物
        String groupId = TransactionMs.createTransactionGroup();
        //切面执行获取查看是否正常
        TransactionVo transactionVo;
        try {
            point.proceed();
            transactionVo = TransactionMs.localTransactionVo(groupId, TransactionType.commit);
        } catch (Throwable throwable) {
            throwable.printStackTrace();
            transactionVo = TransactionMs.localTransactionVo(groupId, TransactionType.rollback);
        }
        TransactionMs.addTransaction(transactionVo);



    }

    @Override
    public int getOrder() {
        return 10000;
    }
}
